function SearchHomeView(params){
	
	var win = Ti.UI.createWindow({
		title: params.title,
		backgroundColor: "#FFF"
	});	
	
	var searchBar = Titanium.UI.createSearchBar({value:""});

	var file = Ti.Filesystem.getFile('xml/reading.xml');
	var contents = file.read();
	var xmltext = Ti.XML.parseString(contents.text);
	
	if ( file.exists() ) {
		var readingChapters = [];
		var searchTableView = Titanium.UI.createTableView({
	  		top: 0,
	  		data:readingChapters, 
	  		search: searchBar, 
	  		filterAttribute:searchBar.value
  		});
  								
		var book = xmltext.documentElement.getElementsByTagName('chapter');
		
		for (var i=0; i<book.length; i++) {

			var chapterTitle = book.item(i).getElementsByTagName('chapternumber').item(0).textContent;
			var abstract = book.item(i).getElementsByTagName('abstract').item(0).textContent;
			var sections = book.item(i).getElementsByTagName('section');

			for (var x=0; x<sections.length; x++){
				
				var sectionNumber = sections.item(x).getElementsByTagName('sectionnumber').item(0).textContent + '\n';
				var sectionText = sections.item(x).getElementsByTagName('text').item(0).textContent + '\n';
				
				if (x==0){
					var textDisplay = sectionNumber + sectionText;
				} 
				else {
					textDisplay = textDisplay + '\n' + sectionNumber + sectionText;	
				}
			}
						
			var row = Ti.UI.createTableViewRow({
				height: Ti.UI.SIZE,
				width: Ti.UI.SIZE,
				hasChild: false,
				detailTitle: chapterTitle,
				detail: abstract,
				className: "tableRow",
			});
		
			var headerLabel = Ti.UI.createLabel({
				text: chapterTitle,
				font: {
					fontSize: "16dp",
					fontFamily: (Ti.Platform.osname === "android") ? "Aller_Bd" : "Aller",
					fontWeight: "bold" //Android will ignore this
				},
				top: "3dp",
				left: "5dp",
				height: Ti.UI.SIZE,
				color: "#000"
			});
			
			var shortDescription = Ti.UI.createLabel({
				text: abstract,
				font:{
					fontSize: "10dp",
					fontFamily: (Ti.Platform.osname === "android") ? "Aller_Lt" : "Aller Light"
				},
				color: "#000",
				top: "24dp",
				height:"auto",
				left: "5dp"
			});

			var sectionText = Ti.UI.createLabel({
				text: textDisplay,
				font:{
					fontSize: "10dp",
					fontFamily: (Ti.Platform.osname === "android") ? "Aller_Lt" : "Aller Light"
				},
				color: "#000",
				top: "36dp",
				height:"auto",
				left: "5dp"
			});				
			
			row.add(headerLabel);
			row.add(shortDescription);
			row.add(sectionText);

			readingChapters.push(row);		
		}
		searchTableView.setData(readingChapters);
	}
	
	searchBar.addEventListener('return', function(e){
		var resultsTableView = Titanium.UI.createTableView({
	  		top: 0,
	  		data:readingChapters, 
	  		search: searchBar, 
	  		filterAttribute:searchBar.value
  		});
  		win.add(resultsTableView);
	});

	win.add(searchTableView);
	return win;
}
module.exports = SearchHomeView;